limsDbextract.editPage = {

    getGridParam : function() {
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-dbextract-edit-list-grid',
            url : limsDbextract.baseUrl + '/queries',
            service : 'limsDbextractServiceImpl',
            dbTable : 'T_LIMS_DBEXTRACT',
            columns : limsDbextract.getEditListColumns(),
            onLoadSuccess : function(data) {
                if (!Gikam.isEmpty(data)) {
                    this.activeRowByIndex(0);
                } else {
                    _this.loadBelowData(-1);
                }
            },
            onRowActive : function(index, row) {
                _this.loadBelowData(row.id);
            },
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    Gikam.preInsert({
                        modalTitle : 'BASELINE.MODULE.DBEXTRACTS.MODAL.ADD',
                        fields : limsDbextract.getBaseInfoFormFields(),
                        url : limsDbextract.baseUrl
                    }).done(function(id) {
                        Gikam.getComp('lims-dbextract-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-dbextract-edit-list-grid').deleteRows(limsDbextract.baseUrl);
                }
            } ]
        }
    },
    loadBelowData : function(id){
        var _this = this;
        Gikam.getAsyncComp('lims-dbextract-config-edit-list-grid').done(function(comp) {
            comp.refresh({
                url : limsDbextractConfig.baseUrl + '/queries',
                requestData : {
                    extractId_SEQ : id
                },
            });
        });
    },
    getSQlConfigGrid : function(){
        var _this = this;
        return {
            type : 'grid',
            id : 'lims-dbextract-config-edit-list-grid',
            service : 'limsDbextractConfigServiceImpl',
            dbTable : 'T_LIMS_DBEXTRACT_CONFIG',
            columns : limsDbextractConfig.getEditListColumns(),
            toolbar : [ {
                type : 'button',
                text : 'GIKAM.BUTTON.INSERT',
                icon : 'add',
                onClick : function() {
                    var grid = Gikam.getComp('lims-dbextract-edit-list-grid');
                    var activedRow = grid.getActivedRow();
                    if(Gikam.isEmpty(activedRow)){
                        Gikam.alert('GIKAM.TIP.CHOOSE_AT_LEAST_ONE_ITEM');
                        return;
                    }

                    Gikam.preInsert({
                        modalTitle : 'BASELINE.MODULE.DBEXTRACTS.MODAL.ADD',
                        fields : limsDbextractConfig.getBaseInfoFormFields(),
                        url : limsDbextractConfig.baseUrl,
                        width : 800,
                        param : {
                            extractId : activedRow.id,
                            enable : '0',
                        },
                    }).done(function(id) {
                        Gikam.getComp('lims-dbextract-config-edit-list-grid').refresh();
                    });
                }
            }, {
                type : 'button',
                text : 'GIKAM.BUTTON.DELETE',
                icon : 'remove-row',
                onClick : function() {
                    Gikam.getComp('lims-dbextract-config-edit-list-grid').deleteRows(limsDbextractConfig.baseUrl);
                }
            } ]
        }
    },

    loadDetailPage : function(id) {
        workspace.window.load(limsDbextract.baseUrl + '/page/detail' + Gikam.param({
            id : id
        }));
    },

    create : function() {
        var _this = this;
        Gikam.create('layout', {
            id : 'lims-dbextract-edit-list-layout',
            renderTo : workspace.window.$dom,
            center : {
                title : 'SQL配置',
                items : [ this.getGridParam() ]
            },
            east : {
                title : '模块',
                width :'70%',
                items : [
                    _this.getSQlConfigGrid()
                ]
            },
        });
    },

    init : function() {
        this.create();
    }
};
